/**
 * customerlog控制器
 *
 * @author sxf
 * @email sxf02615@163.com
 * @date 2025/1/15
 */
package com.sxf.crm.controller;

import com.sxf.crm.dto.CustomerLogDTO;
import com.sxf.crm.service.CustomerLogService;
import com.sxf.crm.util.SecurityUtils;
import lombok.RequiredArgsConstructor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 客户日志管理REST控制器
 */
@RestController
@RequestMapping("/api/customer-logs")
@RequiredArgsConstructor
public class CustomerLogController {
    
    private static final Logger logger = LoggerFactory.getLogger(CustomerLogController.class);
    private final CustomerLogService customerLogService;
    
    @GetMapping("/customer/{customerId}")
    @PreAuthorize("hasAuthority('customer:log:view')")
    public ResponseEntity<List<CustomerLogDTO>> getCustomerLogsByCustomerId(@PathVariable Long customerId) {
        logger.debug("获取客户操作日志: customerId={}", customerId);
        return ResponseEntity.ok(customerLogService.getLogsByCustomerId(customerId));
    }
    
    @GetMapping("/operator/{operatorId}")
    @PreAuthorize("hasAuthority('customer:log:list')")
    public ResponseEntity<List<CustomerLogDTO>> getCustomerLogsByOperator(@PathVariable Long operatorId) {
        logger.debug("获取操作人的操作日志: operatorId={}", operatorId);
        return ResponseEntity.ok(customerLogService.getLogsByOperator(operatorId));
    }
    
    @GetMapping("/my")
    @PreAuthorize("hasAuthority('customer:log:list')")
    public ResponseEntity<List<CustomerLogDTO>> getMyCustomerlogs() {
        Long currentUserId = SecurityUtils.getCurrentUserId();
        logger.debug("获取当前用户的操作日志: userId={}", currentUserId);
        return ResponseEntity.ok(customerLogService.getLogsByOperator(currentUserId));
    }
} 